args thefile comp

cd "`comp'"
insheet using "`thefile'"
sort isocode year month
merge 1:1 isocode year month using "price_shocks_CR.dta" 

drop if _merge==2
drop _merge

sort isocode
merge isocode using "country_region.dta" 
drop if _merge==2

drop _merge

tab region_o, gen(where)
drop *region*

*w_alum51 w_banana32 w_barley26 w_beef34 w_coal5 w_coal6 w_coc_oil18 w_cocoa11 w_coffee12 w_coffee13 w_copper53 w_cotton44 w_fishml20 w_g_oil21 w_gas10 w_gas7 w_gas8 w_gas9 w_gnut19 w_gold58 w_iron52 w_lead54 w_lumber41 w_lumber42 w_meat35 w_mz27 w_nickel56 w_oil1 w_oil2 w_oil3 w_oil4 w_orange33 w_palm_oil22 w_phos46 w_phos47 w_phos48 w_phos49 w_phos50 w_pulp43 w_rice29 w_rubber45 w_shrimp36 w_silver59 w_sorghum28 w_soy23 w_soymeal25 w_soyoil24 w_sugar37 w_sugar38 w_sugar39 w_tea14 w_tea15 w_tea16 w_tea17 w_tin55 w_tobacco40 w_wheat30 w_wheat31 w_zinc57

*actual
*w_alum47 w_banana29 w_beef31 w_coal5 w_coal6 w_coc_oil18 w_cocoa11 w_coffee12 w_coffee13 w_copper49 w_cotton40 w_fishml20 w_gas10 w_gas7 w_gas8 w_gas9 w_gnut19 w_gold54 w_iron48 w_lead50 w_lumber38 w_lumber39 w_meat32 w_mz26 w_nickel52 w_oil1 w_oil2 w_oil3 w_oil4 w_orange30 w_palm_oil22 w_phos42 w_phos43 w_phos44 w_phos45 w_phos46 w_rice27 w_rubber41 w_shrimp33 w_silver55 w_soy23 w_soymeal25 w_soyoil24 w_sugar34 w_sugar35 w_sugar36 w_tea14 w_tea15 w_tea16 w_tea17 w_tin51 w_tobacco37 w_wheat28 w_zinc53


*actual
*                       



*(oil vs minerals vs agricultural commodities)

fac w_gold54 w_iron48 w_alum47 w_nickel52   w_phos42 w_phos43 w_phos44 w_phos45 w_phos46 w_silver55 w_tin51 w_zinc53 w_lead50 w_copper49, pcf fac(1)
predict minerals

fac w_gas10 w_gas7 w_gas8 w_gas9 w_oil1 w_oil2 w_oil3 w_oil4 w_coal5 w_coal6 , pcf fac(1)
predict oil

fac w_banana29 w_beef31 w_coc_oil18 w_coffee12 w_coffee13 w_soy23 w_soymeal25 w_soyoil24 w_sugar34 w_sugar35 w_sugar36 w_tea14 w_tea15 w_tea16 w_tea17 w_tobacco37 w_wheat28 w_rice27 w_orange30 w_palm_oil22 w_gnut19 w_rubber41 w_shrimp33 w_meat32 w_cotton40 w_fishml20 w_lumber38 w_lumber39 w_mz26, pcf fac(1)
predict agricultural 


fac w_*, pcf fac(1)
predict totalcomdata

drop w_*

sort isocode year month

capture confirm variable contig_anyviolence
if !_rc {
	   di in red "contig_anyviolence exists"
}
else {
	sort isocode year month
	merge 1:1 isocode year month using "masterfile_CR.dta" , keepusing(contig_anyviolence)
} 
drop if _merge==2
drop _merge

sort isocode year month

outsheet using temp.csv, replace comma
